#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：NoBad 
@File    ：view.py
@Author  ：LYP
@Date    ：2025/10/30 13:26 
@description :
"""
from rest_framework import serializers
from drf_spectacular.utils import extend_schema, extend_schema_view, OpenApiParameter
from models.models import AIConfig
from tool.base_views import BaseViewSet
from tool.utils import CustomPagination, ApiResponse
from tool.permissions import IsTokenValid


class AISearilizer(serializers.ModelSerializer):
    class Meta:
        model = AIConfig
        fields = '__all__'


@extend_schema(tags=["AI配置管理"])
@extend_schema_view(
    list=extend_schema(summary="获取AI配置表", parameters=[
    ], responses={200: AISearilizer(many=True), }),
    retrieve=extend_schema(summary="获取用户详情,返回是否关注，房间session",
                           responses={200: AISearilizer, 404: "用户不存在"}),
    update=extend_schema(
        summary="更新AI配置", request=AISearilizer),
    partial_update=extend_schema(summary="部分更新AI配置", request=AISearilizer),
    destroy=extend_schema(summary="删除AI配置", description="删除指定用户，仅管理员可操作",
                          responses={204: "删除成功", 404: "用户不存在"}
                          )
)
class AIConfigViewSet(BaseViewSet):
    queryset = AIConfig.objects.all()
    serializer_class = AISearilizer
    pagination_class = CustomPagination
    permission_classes = [IsTokenValid]

    def list(self, request, *args, **kwargs):
        queryset = self.filter_queryset(self.get_queryset())
        page = self.paginate_queryset(queryset)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            # 使用自定义分页响应
            return self.get_paginated_response(serializer.data)
        # 如果没有分页，返回普通响应
        serializer = self.get_serializer(queryset, many=True)
        return ApiResponse(serializer.data)
